package com.neusoft.elm.controller;
import java.math.BigDecimal;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.neusoft.elm.po.Food;
import com.neusoft.elm.service.FoodService;
import com.neusoft.elm.service.impl.FoodServiceImpl;
public class FoodController {
 public Object listFoodByBusinessId(HttpServletRequest request) throws Exception{
 Integer businessId = Integer.valueOf(request.getParameter("businessId"));
 FoodService service = new FoodServiceImpl();
 List<Food> list = service.listFoodByBusinessId(businessId);
 return list;
 }
 
 public Object getFoodById(HttpServletRequest request) throws Exception{
 Integer foodId = Integer.valueOf(request.getParameter("foodId"));
 FoodService service = new FoodServiceImpl();
 Food food = service.getFoodById(foodId);
 return food;
 }
 
 public Object saveFood(HttpServletRequest request) throws Exception{
 String foodName = request.getParameter("foodName");
 String foodExplain = request.getParameter("foodExplain");
 String foodImg = request.getParameter("foodImg");
 BigDecimal foodPrice = new BigDecimal(request.getParameter("foodPrice"));
 Integer businessId = Integer.valueOf(request.getParameter("businessId"));
 String remarks = request.getParameter("remarks");
 
 Food food = new Food();
 food.setFoodName(foodName);
 food.setFoodExplain(foodExplain);
 food.setFoodImg(foodImg);
 food.setFoodPrice(foodPrice);
 food.setBusinessId(businessId);
 food.setRemarks(remarks);
 
 FoodService service = new FoodServiceImpl();
 int result = service.saveFood(food);
 return result;
 }
 
 public Object updateFood(HttpServletRequest request) throws Exception{
 Integer foodId = Integer.valueOf(request.getParameter("foodId"));
 String foodName = request.getParameter("foodName");
 String foodExplain = request.getParameter("foodExplain");
 String foodImg = request.getParameter("foodImg");
 BigDecimal foodPrice = new BigDecimal(request.getParameter("foodPrice"));
 String remarks = request.getParameter("remarks");
 
 Food food = new Food();
 food.setFoodId(foodId);
 food.setFoodName(foodName);
 food.setFoodExplain(foodExplain);
 food.setFoodImg(foodImg);
 food.setFoodPrice(foodPrice);
 food.setRemarks(remarks);
 
 FoodService service = new FoodServiceImpl();
 int result = service.updateFood(food);
 return result;
 }
 
 public Object removeFood(HttpServletRequest request) throws Exception{
 Integer foodId = Integer.valueOf(request.getParameter("foodId"));
 FoodService service = new FoodServiceImpl();
 int result = service.removeFood(foodId);
 return result;
 }
}
